<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="人员姓名" prop="userId">
                <el-select v-model="queryParams.userId" placeholder="选择人员"  @keyup.enter.native="handleQuery">
                                <el-option v-for="item in userList" :key="item.useName" :label="item.nickName"
                                    :value="item.userId">
                                </el-option>
                            </el-select>
            </el-form-item>
            <el-form-item label="手机号码" prop="phonenumber">
                <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['salary:salary:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['salary:salary:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                    v-hasPermi="['salary:salary:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['salary:salary:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="salaryList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="人员姓名" align="center" prop="sysUser.userName" />
            <el-table-column label="所属部门" align="center" prop="sysDept.deptName" />
            <el-table-column label="手机号码" align="center" prop="phonenumber" />
            <el-table-column label="人员状态" align="center" prop="status" >
                <template slot-scope="scope">
                    <span v-if="scope.row.status==0">
                        <el-tag type="success">正常</el-tag>
                    </span>
                    <span v-if="scope.row.status==1">
                        <el-tag type="danger">离职</el-tag>
                    </span>

                </template>
                </el-table-column>
            <el-table-column label="基本工资" align="center" prop="salaryBasic" />
            <el-table-column label="津贴" align="center" prop="salaryAllowance" />
            <el-table-column label="绩效" align="center" prop="salaryPerformance" />
            <el-table-column label="扣款" align="center" prop="salaryDeduction" />
            <el-table-column label="合计" align="center" prop="salaryAmount">
                <template slot-scope="scope">
                    <span>{{ scope.row.salaryBasic + scope.row.salaryAllowance + scope.row.salaryPerformance -
                        scope.row.salaryDeduction }}</span>
                </template>
            </el-table-column>
            <el-table-column label="个人养老保险" align="center" prop="salaryEndowment" />
            <el-table-column label="个人医疗保险" align="center" prop="salaryMedical" />
            <el-table-column label="个人失业保险" align="center" prop="salaryUnemployment" />
            <el-table-column label="个人大额医疗" align="center" prop="salaryLargeMedical" />
            <el-table-column label="个人住房公积金" align="center" prop="salaryHousingFund" />
            <el-table-column label="合计" align="center" prop="salaryThatAmount" />
            <el-table-column label="公司养老保险" align="center" prop="salaryCompanyEndowment" />
            <el-table-column label="公司医疗保险" align="center" prop="salaryCompanyMedical" />
            <el-table-column label="公司失业保险" align="center" prop="salaryCompanyUnemployment" />
            <el-table-column label="公司生育保险" align="center" prop="salaryCompanyMaternity" />
            <el-table-column label="公司医疗保险" align="center" prop="salaryCompanyLargeMedicals" />
            <el-table-column label="公司住房公积金" align="center" prop="salaryCompanyHousingFunds" />
            <el-table-column label="合计" align="center" prop="salaryCompanyAmount" />
            <el-table-column label="本期应补(退)税款" align="center" prop="salaryTaxpayment" />
            <el-table-column label="实发金额" align="center" prop="salaryPaidInAmount" />
            <el-table-column label="签收状态" align="center" prop="auditStatus" >
                <template slot-scope="scope">
                    <span v-if="scope.row.auditStatus==0">
                        <el-tag type="danger">未签收</el-tag>
                    </span>
                    <span v-if="scope.row.auditStatus==1">
                        <el-tag type="success">已签收</el-tag>
                    </span>

                </template>
                </el-table-column>
            <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.auditTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="审核人" align="center" prop="auditPerson" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <span v-if="scope.row.auditStatus==0">
                            <el-button size="mini" type="text" icon="el-icon-check" @click="handleAudit(scope.row)"
                        v-hasPermi="['supplier:supplier:audit']">审核</el-button>
                        </span>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['salary:salary:edit']">修改</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />

        <!-- 添加或修改工资对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
            <el-row :gutter="15">
                <el-form ref="form" :model="form" :rules="rules" size="small" label-width="112px">
                    <el-col :span="24">
                        <el-form-item label="员工姓名" prop="userId">
                            <el-select v-model="form.userId" placeholder="选择人员" @change="blur">
                                <el-option v-for="item in userList" :key="item.useName" :label="item.nickName"
                                    :value="item.userId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="所属部门" prop="deptId">
                            <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门"  width="30%" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="手机号码" prop="phonenumber">
                            <el-input v-model="form.phonenumber" placeholder="请输入手机号码" clearable :style="{ width: '100%' }">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="津贴" prop="salaryAllowance">
                            <el-input type="number"   @blur="paidInAmount" v-model.number="form.salaryAllowance" @change="amount" placeholder="请输入津贴"
                                clearable :style="{ width: '100%' }">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    
                    <el-col :span="11">
                        <el-form-item label="绩效" prop="salaryPerformance">
                            <el-input  type="number"  @blur="paidInAmount" v-model.number="form.salaryPerformance" @change="amount"  placeholder="请输入绩效" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="基本工资" prop="salaryBasic">
                            <el-input type="number"  @blur="paidInAmount" v-model.number="form.salaryBasic"  @change="amount" placeholder="请输入基本工资" clearable :style="{ width: '100%' }">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="扣款" prop="salaryDeduction">
                            <el-input  type="number"  @blur="paidInAmount" v-model.number="form.salaryDeduction"  @change="amount" placeholder="请输入扣款" clearable :style="{ width: '100%' }">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="合计" prop="salaryAmount">
                            <el-input type="number" v-model.number="form.salaryAmount" placeholder="请输入合计" clearable
                                prefix-icon='el-icon-warning' suffix-icon='el-icon-s-tools' :style="{ width: '100%' }" readonly>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="个人养老保险" prop="salaryEndowment">
                            <el-input type="number" @blur="paidInAmount"  @change="thatAmount"  v-model.number="form.salaryEndowment" placeholder="请输入个人养老保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="个人医疗保险" prop="salaryMedical">
                            <el-input type="number" @blur="paidInAmount" @change="thatAmount" v-model.number="form.salaryMedical" placeholder="请输入个人医疗保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="个人失业保险" prop="salaryUnemployment">
                            <el-input type="number" @blur="paidInAmount" @change="thatAmount" v-model.number="form.salaryUnemployment" placeholder="请输入个人失业保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="11">
                        <el-form-item label="个人大额医疗" prop="salaryLargeMedical">
                            <el-input type="number" @blur="paidInAmount" @change="thatAmount" v-model.number="form.salaryLargeMedical" placeholder="请输入个人大额医疗" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="16">
                        <el-form-item label="个人住房公积金" prop="salaryHousingFund">
                            <el-input type="number" @blur="paidInAmount" @change="thatAmount" v-model.number="form.salaryHousingFund" placeholder="请输入个人住房公积金" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="合计" prop="salaryThatAmount">
                            <el-input type="number"  v-model.number="form.salaryThatAmount" placeholder="请输入合计" clearable
                                prefix-icon='el-icon-warning' :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司养老保险" prop="salaryCompanyEndowment">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyEndowment" placeholder="请输入公司养老保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司医疗保险" prop="salaryCompanyMedical">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyMedical" placeholder="请输入公司医疗保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司失业保险" prop="salaryCompanyUnemployment">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyUnemployment" placeholder="请输入公司失业保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司生育保险" prop="salaryCompanyMaternity">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyMaternity" placeholder="请输入公司生育保险" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司大额医疗" prop="salaryCompanyLargeMedicals">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyLargeMedicals" placeholder="请输入公司大额医疗" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公司住房公积金" prop="salaryCompanyHousingFunds">
                            <el-input type="number" @blur="paidInAmount" @change="companyAmount" v-model.number="form.salaryCompanyHousingFunds" placeholder="请输入公司住房公积金" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="合计" prop="salaryCompanyAmount">
                            <el-input type="number" v-model.number="form.salaryCompanyAmount" placeholder="请输入合计" clearable
                                prefix-icon='el-icon-warning' :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="本期补(退)税款" prop="salaryTaxpayment">
                            <el-input type="number" v-model.number="form.salaryTaxpayment" placeholder="请输入本期补(退)税款" clearable
                                :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="实发金额" prop="salaryPaidInAmount">
                            <el-input type="number" v-model.number="form.salaryPaidInAmount" placeholder="请输入实发金额" clearable
                                prefix-icon='el-icon-warning' :style="{ width: '100%' }"></el-input>
                        </el-form-item>
                    </el-col>
                </el-form>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!-- <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="人员姓名" prop="userId">
                    <el-select v-model="form.userId" placeholder="选择人员" @change="blur">
                        <el-option v-for="item in userList" :key="item.useName" :label="item.nickName" :value="item.userId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="所属部门" prop="deptId">
                    <el-select v-model="form.deptId" placeholder="选择部门">
                        <el-option v-for="item in deptList" :key="item.deptName" :label="item.deptName"
                            :value="item.deptId">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="手机号码" prop="phonenumber">
                    <el-input v-model="form.phonenumber" placeholder="请输入手机号码" />
                </el-form-item>
                <el-form-item label="基本工资" prop="salaryBasic">
                    <el-input v-model="form.salaryBasic" placeholder="请输入基本工资" />
                </el-form-item>
                <el-form-item label="津贴" prop="salaryAllowance">
                    <el-input v-model="form.salaryAllowance" placeholder="请输入津贴" />
                </el-form-item>
                <el-form-item label="绩效" prop="salaryPerformance">
                    <el-input v-model="form.salaryPerformance" placeholder="请输入绩效" />
                </el-form-item>
                <el-form-item label="扣款" prop="salaryDeduction">
                    <el-input v-model="form.salaryDeduction" placeholder="请输入扣款" />
                </el-form-item>
                <el-form-item label="合计" prop="salaryAmount">
                    <el-input v-model="form.salaryAmount" placeholder="请输入合计" />
                </el-form-item>
                <el-form-item label="个人养老保险" prop="salaryEndowment">
                    <el-input v-model="form.salaryEndowment" placeholder="请输入个人养老保险" />
                </el-form-item>
                <el-form-item label="个人医疗保险" prop="salaryMedical">
                    <el-input v-model="form.salaryMedical" placeholder="请输入个人医疗保险" />
                </el-form-item>
                <el-form-item label="个人失业保险" prop="salaryUnemployment">
                    <el-input v-model="form.salaryUnemployment" placeholder="请输入个人失业保险" />
                </el-form-item>
                <el-form-item label="个人大额医疗" prop="salaryLargeMedical">
                    <el-input v-model="form.salaryLargeMedical" placeholder="请输入个人大额医疗" />
                </el-form-item>
                <el-form-item label="个人住房公积金" prop="salaryHousingFund">
                    <el-input v-model="form.salaryHousingFund" placeholder="请输入个人住房公积金" />
                </el-form-item>
                <el-form-item label="合计" prop="salaryThatAmount">
                    <el-input v-model="form.salaryThatAmount" placeholder="请输入合计" />
                </el-form-item>
                <el-form-item label="公司养老保险" prop="salaryCompanyEndowment">
                    <el-input v-model="form.salaryCompanyEndowment" placeholder="请输入公司养老保险" />
                </el-form-item>
                <el-form-item label="公司医疗保险" prop="salaryCompanyMedical">
                    <el-input v-model="form.salaryCompanyMedical" placeholder="请输入公司医疗保险" />
                </el-form-item>
                <el-form-item label="公司失业保险" prop="salaryCompanyUnemployment">
                    <el-input v-model="form.salaryCompanyUnemployment" placeholder="请输入公司失业保险" />
                </el-form-item>
                <el-form-item label="公司生育保险" prop="salaryCompanyMaternity">
                    <el-input v-model="form.salaryCompanyMaternity" placeholder="请输入公司生育保险" />
                </el-form-item>
                <el-form-item label="公司医疗保险" prop="salaryCompanyLargeMedicals">
                    <el-input v-model="form.salaryCompanyLargeMedicals" placeholder="请输入公司医疗保险" />
                </el-form-item>
                <el-form-item label="公司住房公积金" prop="salaryCompanyHousingFunds">
                    <el-input v-model="form.salaryCompanyHousingFunds" placeholder="请输入公司住房公积金" />
                </el-form-item>
                <el-form-item label="合计" prop="salaryCompanyAmount">
                    <el-input v-model="form.salaryCompanyAmount" placeholder="请输入合计" />
                </el-form-item>
                <el-form-item label="本期应补(退)税款" prop="salaryTaxpayment">
                    <el-input v-model="form.salaryTaxpayment" placeholder="请输入本期应补(退)税款" />
                </el-form-item>
                <el-form-item label="实发金额" prop="salaryPaidInAmount">
                    <el-input v-model="form.salaryPaidInAmount" placeholder="请输入实发金额" />
                </el-form-item>
                <el-form-item label="审核时间" prop="auditTime">
                    <el-date-picker clearable v-model="form.auditTime" type="date" value-format="yyyy-MM-dd"
                        placeholder="请选择审核时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="审核人" prop="auditPerson">
                    <el-input v-model="form.auditPerson" placeholder="请输入审核人" />
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog> -->
    </div>
</template>
  
<script>
import { auditSalary,listSalary, getSalary, delSalary, addSalary, updateSalary } from "@/api/salary/salary";
import { deptTreeSelect,listUser, getUser } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
    name: "Salary",
    components: { Treeselect },
    data() {
        return {
            salary:{
                salaryId:''
            },
            deptOptions:[],
            userList: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 工资表格数据
            salaryList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                userId: null,
                deptId: null,
                phonenumber: null,
                status: null,
            },
            

            // 表单参数
            form: {
                userId: '',
                deptId:'',
                salaryAmount: 0,
                salaryAllowance: 0,
                salaryBasic: 0,
                salaryDeduction: 0,
                salaryPerformance:0,
                salaryEndowment:0,
                salaryMedical:0,
                salaryUnemployment:0,
                salaryLargeMedical:0,
                salaryHousingFund:0,
                salaryThatAmount:0,
                salaryCompanyEndowment:0,
                salaryCompanyMedical:0,
                salaryCompanyUnemployment:0,
                salaryCompanyMaternity:0,
                salaryCompanyLargeMedicals:0,
                salaryCompanyHousingFunds:0,
                salaryCompanyAmount:0,
                salaryPaidInAmount:0,
                salaryTaxpayment:0,
            },
            // 表单校验
            rules: {
            }
        };
    },
    created() {
        this.getList();
        this.ListUsers();
        this.ListDepts();
    },
    methods: {
        //审核
        handleAudit(row){
            this.salary.salaryId=row.salaryId
            auditSalary(this.salary).then(response=>{
                this.$modal.msgSuccess("审核成功");
                this.getList();
            })
},
        //总工资 计算
       paidInAmount(){
            const salaryAmount = this.form.salaryAmount//基础工资
            const salaryThatAmount= this.form.salaryThatAmount//个人保险
            const salaryCompanyAmount = this.form.salaryCompanyAmount//公司保险
            let salaryTaxpayment=0
           if(salaryAmount>5000){
            salaryTaxpayment=salaryAmount*0.03
           
           }
           let salaryPaidInAmount = salaryAmount - salaryThatAmount - salaryCompanyAmount-salaryTaxpayment
           this.form.salaryTaxpayment = salaryTaxpayment
            this.form.salaryPaidInAmount = salaryPaidInAmount
         
        },
        //公司社保合计 计算
       companyAmount(){
            const salaryCompanyEndowment = this.form.salaryCompanyEndowment//公司养老保险
            const salaryCompanyMedical= this.form.salaryCompanyMedical//公司医疗保险
            const salaryCompanyUnemployment = this.form.salaryCompanyUnemployment//公司失业保险
            const salaryCompanyMaternity = this.form.salaryCompanyMaternity//公司生育保险
            const salaryCompanyLargeMedicals = this.form.salaryCompanyLargeMedicals//公司大额医疗保险
            const salaryCompanyHousingFunds = this.form.salaryCompanyHousingFunds//公司住房公积金   
            let salaryCompanyAmount = salaryCompanyHousingFunds + salaryCompanyLargeMedicals + salaryCompanyMaternity+salaryCompanyUnemployment+salaryCompanyMedical+salaryCompanyEndowment
            this.form.salaryCompanyAmount = salaryCompanyAmount
            
        },
        //个人社保合计 计算
        thatAmount(){
            const salaryEndowment = this.form.salaryEndowment//个人养老保险
            const salaryMedical= this.form.salaryMedical//个人医疗保险
            const salaryUnemployment = this.form.salaryUnemployment//个人失业保险
            const salaryLargeMedical = this.form.salaryLargeMedical//个人大额医疗保险
            const salaryHousingFund = this.form.salaryHousingFund//个人住房公积金
            let salaryThatAmount = salaryEndowment + salaryMedical + salaryUnemployment+salaryLargeMedical+salaryHousingFund
            this.form.salaryThatAmount = salaryThatAmount
        },
         //基本工资合计 计算
        amount() {
            const salaryAllowance = this.form.salaryAllowance//津贴
            const salaryPerformance= this.form.salaryPerformance//绩效
            const salaryBasic = this.form.salaryBasic//基本工资
            const salaryDeduction = this.form.salaryDeduction//扣款
            let salaryAmount = salaryAllowance + salaryPerformance + salaryBasic-salaryDeduction
            this.form.salaryAmount = salaryAmount
        },
        //根据员工获取基本信息
        blur() {
            const userId = this.form.userId;
            getUser(userId).then(response => {
                this.form.phonenumber = response.data.phonenumber;
                this.form.deptId = response.data.deptId;
            });
        },
        //下拉框获取员工
        ListUsers() {
            listUser(null).then(response => {
                this.userList = response.rows;
            })
        },
          //下拉框获取部门
        ListDepts() {
            deptTreeSelect().then(response => {
                this.deptOptions = response.rows;
                console.log(response.rows)
            })
        },

        /** 查询工资列表 */
        getList() {
            this.loading = true;
            listSalary(this.queryParams).then(response => {
                this.salaryList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                salaryId: null,
                userId: null,
                deptId: null,
                phonenumber: null,
                status: null,
                salaryBasic: null,
                salaryAllowance: null,
                salaryPerformance: null,
                salaryDeduction: null,
                salaryAmount: null,
                salaryEndowment: null,
                salaryMedical: null,
                salaryUnemployment: null,
                salaryLargeMedical: null,
                salaryHousingFund: null,
                salaryThatAmount: null,
                salaryCompanyEndowment: null,
                salaryCompanyMedical: null,
                salaryCompanyUnemployment: null,
                salaryCompanyMaternity: null,
                salaryCompanyLargeMedicals: null,
                salaryCompanyHousingFunds: null,
                salaryCompanyAmount: null,
                salaryTaxpayment: null,
                salaryPaidInAmount: null,
                auditStatus: null,
                auditTime: null,
                auditPerson: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.salaryId)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加工资";
            this.ListUsers();
            this.ListDepts();

        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            const salaryId = row.salaryId || this.ids
            console.log(salaryId)
            getSalary(salaryId).then(response => {
                this.form = response.data;
                this.open = true;
                this.title = "修改工资";
                this.ListDepts();
                this.ListUsers();
            });
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.salaryId != null) {
                        updateSalary(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    } else {
                        addSalary(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const salaryIds = row.salaryId || this.ids;
            this.$modal.confirm('是否确认删除工资编号为"' + salaryIds + '"的数据项？').then(function () {
                return delSalary(salaryIds);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('salary/salary/export', {
                ...this.queryParams
            }, `salary_${new Date().getTime()}.xlsx`)
        }
    }
};
</script>
  